lower_word='abcdefghijklmnopqrstuvwxyz'
upper_word='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def is_valid_s(k):   #判断k是否合理
    if k in lower_word:
        return True
    elif k in upper_word:
        return True
    else:
        return False

def encrypt_s(p, k):
    if is_valid_s(k):
        if k in lower_word:
           k_ind = lower_word.index(k)
        else:
             k_ind = upper_word.index(k)
        t = ' '
        for i in p:
            if i in lower_word:
                    t += lower_word[(lower_word.index(i) + k_ind) % 26]
            elif i in upper_word:
                t += upper_word[(upper_word.index(i) + k_ind) % 26]
                pass
            else:
                t += i
        return t
    else:
        return None
def decrypt_s(c, k):
    if is_valid_s(k):
        if k in lower_word:
           k_ind = lower_word.index(k)
        else:
             k_ind = upper_word.index(k)
        t = ' '
        for i in c:
            if i in lower_word:
                t += lower_word[(lower_word.index(i) - k_ind) % 26]
            elif i in upper_word:
                t += upper_word[(upper_word.index(i) - k_ind) % 26]
                pass
            else:
                t += i
        return t
    else:
        return None
if __name__=="__main__":
    p = "Hello,World"
    k = 'b'
    c=encrypt_s(p,k)
    print(c)
    print(decrypt_s(c,k))